﻿using Breeze.WebApi;
using RRKAutohaus.Core;
using RRKAutohaus.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;

namespace RRKAutohaus.Web.Controllers
{
    [BreezeController]
    public class BreezeController : BaseApiController
    {


        public BreezeController(IUnitOfWork uow)
        {
            this.Uow = uow;
        }

        [HttpGet]
        public string Metadata()
        {
            return Uow.DbContext.Metadata();
        }

        [HttpGet]
        public IQueryable<Car> GetAllCars(string carModel,string carType)
        {
            var cars = Uow.Cars.GetAll()
                       .Where(c => c.CarType.ToLower() == carType.ToLower()
                                && c.BrandName.ToLower() == carModel.ToLower());
                                
            return cars;
        }

        [HttpGet]
        public IQueryable<Car> GetFeaturedCars()
        {
            var cars = Uow.Cars.GetFeaturedCars();
            return cars;
        }


        [HttpGet]
        public IQueryable<Car> GetNewCars()
        {
            var cars = Uow.Cars.GetCarsByMonth(DateTime.Now);
            return cars;
        }

        [HttpGet]
        public IQueryable<Image> GetImagesById(int id)
        {
            return Uow.Image.FindEntity(p => p.CarId == id);
        }

        
        [HttpGet]
        public IQueryable<Car> Car()
        {
            return Uow.Cars.GetAll()
                           .Where(c => c.Status == "A");
        }

        [HttpGet]
        public IQueryable<Image> Images()
        {
            return Uow.Image.GetAll()
                            .Where(i => i.Car.Status == "A");
        }

    }
}